说明:省份的字段是province_id,是个int类型(es里面对应为long)。另外id是string,amount是double。
不能对string求sum等运算。
且,es的归类是从外向内的。先处理外层的,再处理内层的。
以省份进行分类,查看每个省份下的订单数量。
{
"fields": [
"show_status"
],
"size": 0,
"aggs": {
"_result": {
"terms": {
"field": "province_id",
"size": 100
},
"aggs": {
"result": {
"value_count": { "field": "id" } }
}
}
}
}
以省份进行分类,查看每个省份下的订单金额总和。
{
"fields": [
"show_status"
],
"size": 0,
"aggs": {
"_result": {
"terms": {
"field": "province_id",
"size": 100
},
"aggs": {
"result": {
"sum": { "field": "amount" } }
}
}
}
}
注:这是elasticsearch的功能,有一些公司是在lucene的基础上自己开发的,能不能支持这样的功能就不可而知了。请各位注意了,避免强行装逼失败。